label: Don't clip text shadows
authorBenjamin Otte <otte@redhat.com>
Thu, 31 Jul 2014 14:10:17 +0000 (16:10 +0200)
committerBenjamin Otte <otte@redhat.com>
Thu, 31 Jul 2014 15:50:24 +0000 (17:50 +0200)
The previous code for computing the clip rectangle forgot to respect
the text-shadow CSS property. This is usually not very visible because
text shadows usually don't extend the ink rectangle by very much.

See attached testcase for an example.

gtk/gtklabel.c
testsuite/reftests/Makefile.am
testsuite/reftests/label-text-shadow-clipping.ref.ui [new file with mode: 0644]
testsuite/reftests/label-text-shadow-clipping.ui [new file with mode: 0644]

index 17b4ca31a351b53b0f79c88d8f01aeb13d65e472..189a1ae99965b5d468fb15f0c46c80f79f35dd07 100644 (file)
@@ -30,6 +30,7 @@
 #include "gtklabel.h"
 #include "gtklabelprivate.h"
 #include "gtkaccellabel.h"
+#include "gtkcssshadowsvalueprivate.h"
 #include "gtkdnd.h"
 #include "gtkmarshalers.h"
 #include "gtkpango.h"
@@ -46,6 +47,7 @@
 #include "gtkbuildable.h"
 #include "gtkimage.h"
 #include "gtkshow.h"
+#include "gtkstylecontextprivate.h"
 #include "gtktooltip.h"
 #include "gtkprivate.h"
 #include "gtktypebuiltins.h"
@@ -3960,17 +3962,21 @@ gtk_label_get_ink_rect (GtkLabel     *label,
                         GdkRectangle *rect)
 {
   GtkLabelPrivate *priv = label->priv;
+  GtkStyleContext *context;
   PangoRectangle ink_rect;
+  GtkBorder extents;
   int x, y;
 
   gtk_label_ensure_layout (label);
   get_layout_location (label, &x, &y);
   pango_layout_get_pixel_extents (priv->layout, &ink_rect, NULL);
+  context = gtk_widget_get_style_context (GTK_WIDGET (label));
+  _gtk_css_shadows_value_get_extents (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_TEXT_SHADOW), &extents);
 
-  rect->x = x + ink_rect.x;
-  rect->width = ink_rect.width;
-  rect->y = y + ink_rect.y;
-  rect->height = ink_rect.height;
+  rect->x = x + ink_rect.x - extents.left;
+  rect->width = ink_rect.width + extents.left + extents.right;
+  rect->y = y + ink_rect.y - extents.top;
+  rect->height = ink_rect.height + extents.top + extents.bottom;
 }
 
 static void
index b0422ed4b14f285212f54ec5be98d61e1faa235c..2607ecc8c73bcc0d70712238de4ef9ecb5fe24d1 100644 (file)
@@ -266,6 +266,8 @@ testdata = \
        label-sizing.ui \
        label-small-ellipsized.ref.ui \
        label-small-ellipsized.ui \
+       label-text-shadow-clipping.ref.ui \
+       label-text-shadow-clipping.ui \
        label-width-chars-dont-shrink.ref.ui \
        label-width-chars-dont-shrink.ui \
        label-wrap-justify.ref.ui \
diff --git a/testsuite/reftests/label-text-shadow-clipping.ref.ui b/testsuite/reftests/label-text-shadow-clipping.ref.ui
new file mode 100644 (file)
index 0000000..c8fa838
--- /dev/null
@@ -0,0 +1,18 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- Generated with glade 3.18.1 -->
+<interface>
+  <requires lib="gtk+" version="3.12"/>
+  <object class="GtkWindow" id="window1">
+    <property name="width_request">500</property>
+    <property name="height_request">100</property>
+    <property name="can_focus">False</property>
+    <property name="type">popup</property>
+    <child>
+      <object class="GtkLabel" id="label1">
+        <property name="visible">True</property>
+        <property name="can_focus">False</property>
+        <property name="label" translatable="yes">Hello World</property>
+      </object>
+    </child>
+  </object>
+</interface>
diff --git a/testsuite/reftests/label-text-shadow-clipping.ui b/testsuite/reftests/label-text-shadow-clipping.ui
new file mode 100644 (file)
index 0000000..018caeb
--- /dev/null
@@ -0,0 +1,32 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- Generated with glade 3.18.1 -->
+<interface>
+  <requires lib="gtk+" version="3.12"/>
+  <object class="GtkWindow" id="window1">
+    <property name="width_request">500</property>
+    <property name="height_request">100</property>
+    <property name="can_focus">False</property>
+    <property name="type">popup</property>
+    <child>
+      <object class="GtkBox" id="box2">
+        <property name="visible">True</property>
+        <property name="can_focus">False</property>
+        <property name="halign">center</property>
+        <property name="valign">center</property>
+        <property name="orientation">vertical</property>
+        <child>
+          <object class="GtkLabel" id="label1">
+            <property name="visible">True</property>
+            <property name="can_focus">False</property>
+            <property name="label" translatable="yes">Hello World</property>
+          </object>
+          <packing>
+            <property name="expand">False</property>
+            <property name="fill">True</property>
+            <property name="position">0</property>
+          </packing>
+        </child>
+      </object>
+    </child>
+  </object>
+</interface>